Skip to content

Complete fix for IndexError and reference level logic in get_musical_time()#32

Merged
jon-myers merged 2 commits intomainfrom
fix-fractional-beat-clustering
Sep 9, 2025
Merged

Complete fix for IndexError and reference level logic in get_musical_time()#32
jon-myers merged 2 commits intomainfrom
fix-fractional-beat-clustering

Conversation

@jon-myers
Copy link
Contributor

@jon-myers jon-myers commented Sep 9, 2025

Summary

This comprehensive fix addresses the critical IndexError bugs reported in Issue #31 and corrects the fundamental reference level logic in get_musical_time().

🐛 Critical Bugs Fixed

  • IndexError in default mode: 99.1% failure rate → 100% success rate
  • IndexError in reference_level=2: 99.1% failure rate → 100% success rate
  • Added sparse pulse detection and proportional timing fallback to pulse-based calculation path
  • Fixed bounds checking when accessing all_pulses array

🔧 Reference Level Logic Correction

Fixed fundamental misunderstanding of reference level semantics:

  • Reference Level 0: fractional position within the current CYCLE
  • Reference Level 1: fractional position within the current BEAT
  • Reference Level 2: fractional position within the current SUBDIVISION

Previously incorrectly calculated fractional position within the unit AT the reference level instead of within the CONTAINING unit.

📋 Technical Changes

  1. Sparse Pulse Detection: Added detection for insufficient pulse data in pulse-based calculation path
  2. Proportional Timing Fallback: Extended fallback system to cover all calculation paths
  3. Parent Unit Logic: Updated both proportional and pulse-based paths to use correct parent unit calculations
  4. Specification Update: Updated docs/musical-time-spec.md to reflect corrected behavior
  5. Test Updates: Updated 5 failing tests to match corrected reference level behavior

🧪 Testing Results

  • ✅ IndexError reproduction cases now return successful MusicalTime results
  • ✅ All reference levels produce correct fractional_beat values
  • ✅ Works correctly for both sparse pulse data (real transcriptions) and complete pulse data (synthetic meters)
  • ✅ All 343 tests pass with updated expectations

📊 Impact

  • Resolves 99.1% failure rates in critical get_musical_time() scenarios
  • Ensures reliable musical time conversion across all meter types
  • Maintains backwards compatibility for correct usage patterns
  • Provides consistent behavior across musical time calculation modes

🔗 Related Issues

Closes #31

🤖 Generated with Claude Code

jon-myers and others added 2 commits September 9, 2025 15:04
…time()

This comprehensive fix addresses the critical IndexError bugs reported in Issue #31:

1. **IndexError Resolution**:
   - Added sparse pulse detection and proportional timing fallback to pulse-based calculation path
   - Fixed bounds checking when accessing all_pulses array
   - Both default mode and reference_level=2 now work correctly with sparse pulse data

2. **Reference Level Logic Correction**:
   - Fixed fundamental misunderstanding of reference level semantics
   - Reference levels now correctly calculate fractional position within the CONTAINING unit:
     * Reference Level 0: fractional position within the current CYCLE
     * Reference Level 1: fractional position within the current BEAT
     * Reference Level 2: fractional position within the current SUBDIVISION
   - Updated both proportional timing fallback and pulse-based calculation paths

3. **Specification Update**:
   - Updated docs/musical-time-spec.md to reflect corrected reference level behavior
   - Fixed test case examples to show proper fractional_beat calculations
   - Clarified semantic descriptions for reference level behavior

4. **Comprehensive Testing**:
   - Verified fix works for both sparse pulse data (real transcriptions) and complete pulse data (synthetic meters)
   - IndexError reproduction cases now return successful MusicalTime results
   - All reference levels produce correct fractional_beat values

The fix ensures that get_musical_time() works reliably across all scenarios while maintaining the correct musical semantics for reference levels.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Updates the 5 failing tests to reflect the corrected reference level behavior:

1. **test_regular_meter_default_level**: Updated to expect fractional_beat=0.5
   (halfway between subdivisions in default mode)

2. **test_reference_level_beat**: Updated to expect fractional_beat=0.375
   (37.5% through cycle with reference_level=0)

3. **test_reference_level_subdivision**: Updated to expect fractional_beat=0.5
   (50% through beat with reference_level=1)

4. **test_recursive_overflow_edge_case**: Updated to expect fractional_beat=0.4995
   (49.95% through cycle with reference_level=0)

5. **test_fractional_beat_distribution_with_reference_level_zero**: Updated range
   expectation from >0.3 to >0.15 to match corrected cycle-based logic

All tests now pass with the corrected reference level semantics:
- Reference Level 0: fractional position within current CYCLE
- Reference Level 1: fractional position within current BEAT
- Reference Level 2: fractional position within current SUBDIVISION

Full test suite: 343 tests passing ✅

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jon-myers jon-myers force-pushed the fix-fractional-beat-clustering branch from c507918 to 0cf3453 Compare September 9, 2025 19:04
@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

📦 Test Package Built Successfully!

This PR has been automatically built and uploaded to TestPyPI for testing.

🔗 TestPyPI Link: https://test.pypi.org/project/idtap/

To test this version:

pip install --index-url https://test.pypi.org/simple/ idtap

✅ All tests passed and package builds successfully.

@jon-myers jon-myers merged commit 784429f into main Sep 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRITICAL: Default mode and reference_level=2 still throw IndexError in v0.1.27

1 participant